package com.example.controller;

import com.example.pojo.Emp1;
import com.example.pojo.PageBean;
import com.example.pojo.Result;
import com.example.service.Emp1Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/emps")
public class Emp1Controller {
    @Autowired
    Emp1Service emp1Service;
    @GetMapping
    public Result page(@RequestParam(defaultValue = "1") Integer page, //页码数
                       @RequestParam(defaultValue = "10") Integer pagesize,//每页展示多少条
                       String name, Short gender,
                       @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
                       @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end
                       ){
        log.info("分页条件查询");
            PageBean pageBean =emp1Service.page(page,pagesize,name,gender,begin,end);
        return Result.success(pageBean);
    }
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        log.info("批量删除");
        emp1Service.deleteById(ids);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id){
        log.info("根据id查询");
        Emp1 emp1=emp1Service.selectById(id);
        return Result.success(emp1);
    }
    @PutMapping
    public Result update(@RequestBody Emp1 emp1){
        log.info("修改数据");
        emp1Service.update(emp1);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Emp1 emp1){
        log.info("添加数据");
        emp1Service.add(emp1);
        return Result.success();
    }
}
